
<template>
  <div>
    <el-container>
      <el-aside :class="isCollapse ? 's' : 'w'">
        <div class="logo" v-show="!isCollapse">
          <p>管理系统</p>
        </div>
        <div class="logo" v-show="isCollapse">
          <p>管理</p>
        </div>
        <el-menu
          :default-active="editableTabsValue"
          class="el-menu-vertical-demo"
          @select="handleOpen"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse"
        >
          <el-menu-item index="1" @click="ck(1, '首页','shouye')">
            <i class="el-icon-house"></i>
            <span>首页</span>
          </el-menu-item>
          <el-menu-item index="2" @click="ck(2, '商品管理','shangpingye')">
            <i class="el-icon-document"></i>
            <span slot="title">商品管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-menu
            :default-active="tabIndex"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
          >
            <div class="menu-icon" @click="isCollapse1">
              <i class="el-icon-menu"></i>
            </div>

            <el-breadcrumb separator-class="el-icon-arrow-right" style=" position: absolute; width: 500px;height: 100%;margin-left: 70px;">
              <el-breadcrumb-item
                v-for="(shu1, index1) in shu"
                :key="index1"
              >
            <span @click="ck1(String(index1 + 1), String(shu1)) " 
            :class="tabIndex== String(index1+1)?'bulll2':'bullll'"
            >{{ shu1 }}</span>    
              </el-breadcrumb-item>
            </el-breadcrumb>

          <span style="float: right; width: 100px; height: 50px;margin-left: 100px;">
              <img  @click="qiehuan" style="position: absolute; width: 50px; height: 50px;margin-top: 5px; " src="./zizujian/time.png" alt="">
              <div style="position: absolute; margin-top: 55px; display: flex; flex-wrap: wrap" v-show="qiehuan1">
                <div style="margin-left: 70px;  width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 10px solid #fff;"></div>
                <div style=" width: 100px; height: 70px; background-color: #fff;">
                <div style=" width: 100px; height: 30px;line-height:30px;margin-top: 5px; " class="jianbuian"  @click="ck(1,'首页','shouye'),qiehuan1=false"> 个人中心</div>
                <div style="width: 100px; height: 30px;;line-height:30px;" class="jianbuian" @click="ck(1,1,'denglu')">退出登录</div>
                </div>
             </div>
             
          </span>
          
            
          </el-menu>
        
          <!-- <div class="line"></div> -->
        </el-header>
        <el-main>
          <div style="height: 25px; display: flex ;margin-bottom: 10px;">
            <div style="width: 55px;"></div>
            <div
              style="margin-right: 5px; height: 25px ;border-radius:5px ;"
              v-for="(shu1, index) in shu"
              :key="index"
              @click="SHU1(index)"
              :class="SHUshu == index ? 'SHU' : 'SHU1'"
              @mouseover="yiru(index)"
              @mouseout="yiru(-1)"
            >
              {{ shu1 }}
              <i
                v-show="index == cloSable"
                class="el-icon-close"
                @click="ckx(index)"
              ></i>
            </div>
          </div>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>

export default {
  data() {
    return {
      shu: ["首页"],
      cloSable: -1,
      isCollapse: true,
      Hshu:["首页", "商品管理", "用户管理", "页面1", "页面2"],
      qiehuan1:false,
      editableTabsValue: "1",
      tabIndex: "1",
      SHUshu: 0,
    };
  },
  created() {},
  computed: {},
  mounted() {
   let shu1=Number(this.$store.state.editableTabsValue)
   let shu=["首页", "商品管理", "用户管理", "页面1", "页面2"];
   let cc=['shouye','shangpingye']
   if(cc.indexOf(cc[shu1-1])!=-1){
    this.ck(this.$store.state.editableTabsValue,shu[shu1-1],cc[shu1-1])
   }
  
},
beforeRouteEnter (to, from, next) {
    if (JSON.parse(localStorage.getItem("vuex")).bool) {
    next();
  } else {
    next(false);
  }
  },
  methods: {
    qiehuan(){
         this.qiehuan1=! this.qiehuan1
    }
    ,
    ckx(e) {
      if (e != 0) {
        this.shu.splice(e, 1);
        if (this.SHUshu >= e) {
          this.SHUshu -= 1;
          this.tabIndex = (this.SHUshu + 1).toString();
          let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
          this.editableTabsValue = (
            shu.indexOf(this.shu[this.tabIndex - 1]) + 1
          ).toString();
          let cc=['shouye','shangpingye']
          this.$router.push({ name:cc[this.editableTabsValue-1] ,query:{ id:this.$route.query.id} });
        }
      }
    },

    SHU1(e) {
      let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
      this.tabIndex = (this.shu.indexOf(this.shu[e]) + 1).toString();
      this.editableTabsValue = (shu.indexOf(this.shu[e]) + 1).toString();
      let cc=['shouye','shangpingye']
      this.$router.push({ name:cc[this.editableTabsValue-1],query:{ id:this.$route.query.id} });
      this.SHUshu = e;
    },
    yiru(e) {
      if (e == -1) {
        this.cloSable = e;
      } else {
        this.cloSable = e;
      }
    },
    isCollapse1() {
      this.isCollapse = !this.isCollapse;
    },
    handleSelect(key, keyPath) {
      // console.log(key, keyPath);
    },
    ck(e, l,m) {
      if(m=='denglu'){
        this.$store.commit('akk')
      }
      if (!this.shu.includes(l)) {
        this.shu.push(l);
      }
      if (Boolean(e)) {
        this.tabIndex = (this.shu.indexOf(l) + 1).toString();
        this.editableTabsValue = `${e}`;
        this.SHUshu = this.shu.indexOf(l);
        this.$store.commit('arc',this.editableTabsValue)
      }
      this.$router.push({ name:m,query:{ id:this.$route.query.id}});
      
    },
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    tabclick() {
      console.log(1);
    },
    removeTab(targetName) {
      let tabs = this.shu;
      let activeName = this.editableTabsValue;
      if (activeName === targetName) {
        tabs.forEach((tab, index) => {
          if (tab === targetName) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab;
            }
          }
        });
      }
      // 当标签页数组中只剩下一个标签页时，不再执行删除操作
      if (tabs.length > 1 && targetName !== "首页") {
        this.editableTabsValue = activeName;
        this.shu = tabs.filter((tab) => tab !== targetName);
      }
    },

    ck1(e, l) {
      let shu = ["首页", "商品管理", "用户管理", "页面1", "页面2"];
      this.editableTabsValue = (shu.indexOf(l) + 1).toString();
      this.tabIndex = (this.shu.indexOf(l) + 1).toString();
      this.SHUshu = e - 1;
      let cc=['shouye','shangpingye']
      this.$router.push({ name:cc[this.editableTabsValue-1],query:{ id:this.$route.query.id} });
    }
  },
};
</script>

<style lang='less' scoped>
.bulll2{
  color: #fff !important;

}
.bullll{
  color: #000;

}
.el-breadcrumb {
  line-height: 60px;
}
.jianbuian:hover{
  background-color: #40a0ff82;
  color: #409eff;
}
.SHU {
  background-color: #409eff;
  color: #fff;
}
.SHU1 {
  outline: 1px solid #409eff;
  background-color: #fff;
  color: #409eff;
}
.SHU1:hover {
  background-color: #409eff;
  color: #fff;
}
.logo {
  color: #fff;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
}
/deep/.el-tabs__item {
  height: 25px !important;
  line-height: 20px !important;
  text-align: center;
}
.w {
  width: 200px !important;
}

.s {
  width: 60px !important;
}

.el-menu {
  border: none;
  background-color: rgb(88, 236, 93);
}

.el-header {
  .el-menu-item.is-active {
    color: #e9eef3 !important;
  }
  background-color: rgb(88, 236, 93);
  color: #333;
  text-align: center;
  line-height: 40px;
  height: 60px;
}

.el-aside {
  ul {
    text-align: left;
  }
  background-color: #545c64;
  color: #e9eef3;
  text-align: center;
}

/deep/.el-menu-item.is-active {
  color: rgb(0, 255, 8) !important;
}

.el-menu--horizontal > .el-menu-item {
  color: #000;
}

.el-main {
  /deep/.el-tabs__item.is-active {
    background-color: #409eff;
    color: #e9eef3;
  }
  background-color: #e9eef3;
  color: #333;
  margin: 0;
  padding: 0px;
  // text-align: center;
}

.el-container {
  height: 100vh;
}

.menu-icon {
  float: left;
  width: 50px;
  height: 40px;
  background-color: azure;
  margin: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
}

.line {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: #fff;
}

.tabs-wrapper {
  outline: 1px solid red;
}
</style>



